package com.wicket.okrframework.biz.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.wicket.okrframework.biz.service.dto.req.*;
import com.wicket.okrframework.biz.service.dto.res.*;
import com.wicket.okrframework.common.exception.BizException;
import com.wicket.okrframework.common.util.CommonFunctionHelper;
import com.wicket.okrframework.common.util.RedisUtil;
import java.util.List;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.wicket.okrframework.base.service.MPrivacyDistributionService;
import com.wicket.okrframework.dal.po.mbg.PrivacyDistribution;
import com.wicket.okrframework.base.service.dto.req.BatchQueryTributPowerListReq;
import java.util.ArrayList;
import cn.hutool.core.collection.CollectionUtil;
import com.wicket.okrframework.common.exception.Assert;
import com.wicket.okrframework.biz.service.nb.NbEvaSystem;

/**
 * @author ：
 * @date ：
 *
 *
 * @version 1.0
 */
@Service
public class EvaSystemServiceImpl
  implements com.wicket.okrframework.biz.service.EvaSystemService {

  @Resource
  private RedisUtil redisUtil;
@Resource
  private MPrivacyDistributionService mPrivacyDistributionService;
@Resource
  private NbEvaSystem nbEvaSystem;
/**
   * D1-2查询绩效规划模板管理权限列表(公共)[3096]
   * gen by moon at 5/21/2024, 2:02:22 AM
   */
  @Trace(operationName = "D1-2查询绩效规划模板管理权限列表(公共)")
  @Tags({@Tag(key = "参数",value = "arg[0]"),
            @Tag(key = "返回值",value = "returnedObj")})
  @Transactional(rollbackFor=Exception.class)
  @Override
  public QueryPlanKpiTempMgtPowerListComRespDto queryPlanKpiTempMgtPowerListCom(QueryPlanKpiTempMgtPowerListComReqDto reqDto){
    
      
      List<PrivacyDistribution> listPrivacyDistribution_1 =new ArrayList<>();
//步骤0: D1查询用于权限角色列表(公共) - queryRoleOfPowerListCom
     //ModelCode: getUserRoleListFromRedis
        QueryRoleOfPowerListComRespDto getUserRoleListFromRedisRes = null;
    QueryRoleOfPowerListComReqDto getUserRoleListFromRedisReq=new QueryRoleOfPowerListComReqDto();
  getUserRoleListFromRedisReq.setOriginalRoleMemberId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecOriginalRoleMemberId());//CURRENT_ORIGINAL_ROLE_MEMBERID//sourceId:104952_1
getUserRoleListFromRedisReq.setSubjectLifeCycle("CURRENTLY_VALID");//sourceId:1811484_1
  
    /*D1查询用于权限角色列表(公共)[2189]  用于登录时，异步获取登录用户所属的角色信息列表 */
    Assert.isNull(getUserRoleListFromRedisReq.getOriginalRoleMemberId(),"D1-2查询绩效规划模板管理权限列表(公共)-D1查询用于权限角色列表(公共)-身份人员ID不能为空",false);
Assert.isNull(getUserRoleListFromRedisReq.getSubjectLifeCycle(),"D1-2查询绩效规划模板管理权限列表(公共)-D1查询用于权限角色列表(公共)-主体生命周期不能为空",false);
      getUserRoleListFromRedisRes = nbEvaSystem.queryRoleOfPowerListCom(getUserRoleListFromRedisReq);
      
      
      
    
//步骤1: 1-2-12批量查询权限分配列表 - batchQueryTributPowerList
     List<PrivacyDistribution> listPrivacyDistribution =new ArrayList<>();
    BatchQueryTributPowerListReq batchQueryTributPowerListReq=new BatchQueryTributPowerListReq();
  batchQueryTributPowerListReq.setIsDataPrivacy("TRUE");//sourceId:104958_1
batchQueryTributPowerListReq.setPrivacyCategory("SUB_DATA_PRIVACY");//sourceId:104959_1
batchQueryTributPowerListReq.setBusinessPurposes("ALL");//sourceId:105454_1
batchQueryTributPowerListReq.setSubjectLifeCycle("CURRENTLY_VALID");//sourceId:104956_1
if(getUserRoleListFromRedisRes!= null&&  getUserRoleListFromRedisRes.getRoleRelList() !=null&& !CollectionUtil.isEmpty(getUserRoleListFromRedisRes.getRoleRelList())){
      batchQueryTributPowerListReq.setTributPowerList(getUserRoleListFromRedisRes.getRoleRelList().stream().map(item->item.getRoleId())
        .collect(Collectors.toList()));/*list-to-strings*///sourceId:104954_1
    }
if(reqDto!=null){
      batchQueryTributPowerListReq.setTypeCode(reqDto.getTypeCode());//SimpleFieldAssign//sourceId:104953_1
batchQueryTributPowerListReq.setDataModel(reqDto.getDataModel());//SimpleFieldAssign//sourceId:104960_1
    }
  
    /*1-2-12批量查询权限分配列表[702]   */
    Assert.isNull(batchQueryTributPowerListReq.getTypeCode(),"D1-2查询绩效规划模板管理权限列表(公共)-1-2-12批量查询权限分配列表-分配对象类型编码不能为空",false);
Assert.isNull(batchQueryTributPowerListReq.getIsDataPrivacy(),"D1-2查询绩效规划模板管理权限列表(公共)-1-2-12批量查询权限分配列表-是否数据权限不能为空",false);
Assert.isNull(batchQueryTributPowerListReq.getDataModel(),"D1-2查询绩效规划模板管理权限列表(公共)-1-2-12批量查询权限分配列表-数据父模型编码不能为空",false);
Assert.isNull(batchQueryTributPowerListReq.getPrivacyCategory(),"D1-2查询绩效规划模板管理权限列表(公共)-1-2-12批量查询权限分配列表-权限类别不能为空",false);
Assert.isNull(batchQueryTributPowerListReq.getBusinessPurposes(),"D1-2查询绩效规划模板管理权限列表(公共)-1-2-12批量查询权限分配列表-权限业务用途不能为空",false);
Assert.isNull(batchQueryTributPowerListReq.getSubjectLifeCycle(),"D1-2查询绩效规划模板管理权限列表(公共)-1-2-12批量查询权限分配列表-主体生命周期不能为空",false);
      listPrivacyDistribution = mPrivacyDistributionService.batchQueryTributPowerList(batchQueryTributPowerListReq)/*vcase invoke 本地 method 方法调用;*/;
      
      
      listPrivacyDistribution_1 = listPrivacyDistribution;
    
QueryPlanKpiTempMgtPowerListComRespDto retData = new QueryPlanKpiTempMgtPowerListComRespDto();
  retData.setTributPowerList(listPrivacyDistribution_1.stream().map(item -> BeanUtil.toBean(item, TributPowerDto.class)).collect(Collectors.toList()));//objList-to-objLists//sourceId:104961_1
  

  
  
return retData;
  }
  //
}
